<?php
//  This file is part of EkkinCMS.
//
//  EkkinCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  EkkinCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with EkkinCMS.  If not, see <http://www.gnu.org/licenses/>.

include_once("ext_lib/simple_html_dom.php");

function execute_flvplayer($site_content){

	$html = str_get_html($site_content);

	foreach($html->find("a") as $element){
		if (str_endswith($element->href, ".flv")){
			$thumb = "";
			foreach($element->find("img") as $img){
				$thumb = $img->src;
				$description = $img->title;
				$duration = $img->alt;
			}

			$flv_content = generate_flvplayer($element->href, $thumb, $description, $duration);
			$element->innertext = $flv_content;
			$element->href = "";

		}
	}

	return $html->save();
}

function generate_flvplayer($url, $thumb, $description, $duration){

	if ($thumb != ""){
		$autoplay = "true";
	} else {
		$autoplay = "false";
	}

	$s = random_string(10);

    $html = "
    <!-- this A tag is where your Flowplayer will be placed. it can be anywhere -->
		<!--a
			 href=\"$url\"
			 style=\"display:block;width:250px;height:188px\"
			 id=\"player$s\" style=\"background-image: url('$thumb');\">

		</a -->
		<style>
		/* player container */
div.player$s {
	height:206px;
	width:275px;
	border:1px solid #5E5E5E;
	border-radius: 4px 4px;
	-moz-border-radius: 4px 4px;



	cursor:pointer;
	float:left;
	text-align:center;
	margin-right:15px;
}

/* play button */
div.player$s img {
	margin-top:40px;
}

/* info area */
div.player$s div.info {
	height:30px;
	background:#000 url(http://flowplayer.org/img/global/gradient/h80.png) repeat-x;
	opacity:0.7;
	color:#fff;
	margin-top:40px;
	text-align:left;
	padding:5px 15px;
	font-family:\"bitstream vera sans\",\"trebuchet ms\";
	font-size:12px;
	border-top:1px solid #ccc;
}

/* duration data inside info area */
div.player$s div.info span {
	color:#99FF99;
	display:block;
	font-weight:bold;
}

		</style>
		<div class=\"player$s\"
				href=\"$url\"
				style=\"background-image:url($thumb)\">

			<!-- play button -->
			<img src=\"http://flowplayer.org/img/player/btn/play_large.png\" alt=\"Play this video\" />

			<!-- info -->
			<div class=\"info\">
				$description
				<span>"._("duration").": $duration</span>
			</div>

		</div>

		<!-- this will install flowplayer inside previous A- tag. -->
		<script>
			flowplayer(\"div.player$s\", \"ext_lib/flowplayer/flowplayer-3.2.5.swf\",{
			clip: {
			autoPlay: $autoplay,
			autoBuffering: true
			}
			});
		</script>
    ";

    return $html;


}


?>
